<template>
  <div id="order">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.orderSn" placeholder="订单号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" border v-loading="dataListLoading" style="width: 100%;">
      <el-table-column v-for="row in headerList" :key="row.key" :prop="row.key" :min-width="row.width" :label="row.label" header-align="center" align="center"></el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" width="200" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="seeDetail(scope.row)">查看详情</el-button>
          <el-button type="text" size="small" v-if="scope.row.status=='0'" @click="statusChange(scope.row, '1')">审核通过</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <order-detail ref="orderDetail"/>
  </div>
</template>

<script>
import orderDetail from './orderDetail.vue'
export default {
  components: { orderDetail },
  data () {
    return {
      dataForm: {
        orderSn: ''
      },
      headerList: [{
        key: 'orderSn',
        label: '订单编号',
        width: '150'
      },
      {
        key: 'clothingTypeName',
        label: '服装类型',
        width: '150'
      },
      {
        key: 'designerName',
        label: '设计师',
        width: '150'
      },
      {
        key: 'statusName',
        label: '订单状态',
        width: '150'
      },
      {
        key: 'orderDescribe',
        label: '订单描述',
        width: '150'
      },
      {
        key: 'customerAmount',
        label: '价格(元)',
        width: '150'
      }],
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false
    }
  },
  activated () {
    this.getDataList()
  },
  methods: {
    // 查看详情
    seeDetail (row) {
      this.$refs.orderDetail.init(row)
    },
    // 状态改变
    statusChange (row, status) {
      this.$http({
        url: this.$http.adornUrl('/sys/clothingorder/changestatus/' + row.id + '/' + status),
        method: 'post'
      }).then(({ data: res }) => {
        if (res && res.code === 0) {
          this.$message.success('操作成功!')
          this.getDataList()
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/sys/clothingorder/orderpage'),
        method: 'get',
        params: this.$http.adornParams({
          'page': this.pageIndex,
          'limit': this.pageSize,
          'orderSn': this.dataForm.orderSn
        })
      }).then(({ data: res }) => {
        if (res && res.code === 0) {
          this.dataList = res.data.list
          this.totalPage = res.data.total
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    }
  }
}
</script>
